#!/usr/bin/env node

'use strict';
const program = require('commander');
const fs = require('fs');
const process = require('process');
const packageJson = require('../package.json');
const info = require("./info.js");
const chalk = require('chalk');
program
    .version(packageJson.version, '-v --version')
    .command('new <cmd-order> <project-name>')
    .description('创建新项目')
    .action((cmd, option) => {
        const projectName = option; //项目名称
        const cmd_order = cmd; //模版命令
        if (fs.existsSync(projectName)) {
            //检查是否存在该文件夹
            info.checkFile(projectName, () => {
                info.downloadFile(projectName, cmd_order, () => {
                    console.log(`${chalk.green('拉取远程模板仓库成功！')}`);
                })
            });
        } else {
            //不存在拉取模版
            info.downloadFile(projectName, cmd_order, () => {
                console.log(`${chalk.green('拉取远程模板仓库成功！')}`);
            });
        }
    });

program.parse(process.argv);